import Vue from 'vue'

export default {
    state: {
        assetSystemFlag: false, // 是否有资产管理系统的标记
        shenpiFlag: false, // 是否在审批应用的权限
        isUsedLanLing: false, // 是否使用蓝凌OA
        voiceMaskVis: false, // 是否显示语音遮罩层
        fromTabVoiceData: null, // 从Tab进入ai页面的语音数据
        voiceCancelMode: false, // 是否处于录音取消模式（上滑状态）
        commonHeight: {
            statusBarHeight: 0, // 状态栏高度
            navigationBarHeight: 0, // 导航栏高度
            navHeight: 0, // 总体高度
            navWidth: 0,
            capsuleRightDistance: 0
        },
    },
    actions: {
        // 用户是否有资产管理系统
        async getWebAppsFlag({ commit }) {
            return new Promise(async (resolve, reject) => {
                let res = await Vue.Geting(Vue.api.memberWebApps)
                if (res && res.code === '0') {
                    let webApps = res.data || []
                    let assetSystemFlag = false
                    let shenpiFlag = false
                    for (let item of webApps) {
                        let apps = item.apps
                        let findIndex = apps.findIndex(sub => sub.refDevopsAppId === '849298428788744192') // 找出PC端是否有资产管理的应用
                        if (findIndex > -1) {
                            assetSystemFlag = true
                        }
                        let shenpiIndex = apps.findIndex(sub => sub.refDevopsAppId === '467711464535228416') // 找出PC端是否有审批的应用
                        if (shenpiIndex > -1) {
                            shenpiFlag = true
                        }
                    }
                    console.log(shenpiFlag, 'shenpiFlag')
                    commit('SetAssetSystemFlag', assetSystemFlag)
                    commit('SetShenpiFlag', shenpiFlag)
                }
                resolve(true)
            })
        }
    },
    mutations: {
        // 设置是否显示资产系统
        SetAssetSystemFlag(state, flag) {
            state.assetSystemFlag = flag
        },
        // 设置顶部高度数据
        setCommonHeight(state, data) {
            state.commonHeight = data;
        },
        // 设置是否显示资产系统
        SetShenpiFlag(state, flag) {
            state.shenpiFlag = flag
        },
        // 是否使用了蓝凌
        SetIsUsedLanLing(state, flag) {
            state.isUsedLanLing = flag
        },
        setVoiceMaskVis(state, flag) {
            state.voiceMaskVis = flag
        },
        setFromTabVoiceData(state, data) {
            state.fromTabVoiceData = data
        },
        setVoiceCancelMode(state, flag) {
            state.voiceCancelMode = flag
        }
    }
}
